package com.zbkj.front.controller.assistant;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.front.controller.assistant.service.AssistantMessageService;
import com.zbkj.service.assistant.model.request.AssistantMessageFeedbackRequest;
import com.zbkj.service.assistant.model.request.AssistantMessageReadRequest;
import com.zbkj.service.assistant.model.request.AssistantMessageUserSearchRequest;
import com.zbkj.service.assistant.model.request.AssistantMessageUserSendRequest;
import com.zbkj.service.assistant.model.vo.AssistantMessageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 消息表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/front/assistant/message")
@Api(tags = "客服-消息表") //配合swagger使用
@RequiredArgsConstructor
public class AssistantMessageController {

    private final AssistantMessageService assistantMessageService;
    private final FrontTokenComponent frontTokenComponent;

    @ApiOperation(value = "分页列表") //配合swagger使用
    @GetMapping("/list")
    public CommonResult<CommonPage<AssistantMessageVO>>  getList(@Validated AssistantMessageUserSearchRequest request, @Validated PageParamRequest pageParamRequest) {
        Integer userId = frontTokenComponent.getUserId();
        CommonPage<AssistantMessageVO> assistantMessageCommonPage = CommonPage.restPage(assistantMessageService.getUserMessageList(request, pageParamRequest, userId));
        return CommonResult.success(assistantMessageCommonPage);
    }

    @ApiOperation(value = "发送消息")
    @PostMapping("/send")
    public CommonResult<AssistantMessageVO> save(@RequestBody @Validated AssistantMessageUserSendRequest request) {
        Integer userId = frontTokenComponent.getUserId();
        AssistantMessageVO assistantMessage = assistantMessageService.sendByUser(request, userId);
        return CommonResult.success(assistantMessage);
    }

    @ApiOperation(value = "读消息")
    @PostMapping("/read")
    public CommonResult<Void> read(@RequestBody @Validated AssistantMessageReadRequest request) {
        assistantMessageService.read(request.getMessageId());
        return CommonResult.success();
    }

    @ApiOperation(value = "进行评价")
    @PostMapping("/feedback")
    public CommonResult<Void> feedback(@RequestBody @Validated AssistantMessageFeedbackRequest request) {
        Integer userId = frontTokenComponent.getUserId();
        assistantMessageService.feedback(request, userId);
        return CommonResult.success();
    }

//    /**
//     * 删除消息表
//     * @param id Integer
//     * @author keNan
//     * @since 2025-06-11
//     */
//    @ApiOperation(value = "删除")
//    @RequestMapping(value = "/delete", method = RequestMethod.GET)
//    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
//        if(assistantMessageService.removeById(id)) {
//            return CommonResult.success();
//        } else {
//            return CommonResult.failed();
//        }
//    }
//
//    /**
//     * 修改消息表
//     * @param id integer id
//     * @param assistantMessageRequest 修改参数
//     * @author keNan
//     * @since 2025-06-11
//     */
//    @ApiOperation(value = "修改")
//    @RequestMapping(value = "/update", method = RequestMethod.POST)
//    public CommonResult<String> update(@RequestParam Integer id, @RequestBody @Validated AssistantMessageRequest assistantMessageRequest) {
//        AssistantMessage assistantMessage = new AssistantMessage();
//        BeanUtils.copyProperties(assistantMessageRequest, assistantMessage);
//        assistantMessage.setId(id);
//
//        if(assistantMessageService.updateById(assistantMessage)) {
//            return CommonResult.success();
//        } else {
//            return CommonResult.failed();
//        }
//    }
//
//    /**
//     * 查询消息表信息
//     * @param id Integer
//     * @author keNan
//     * @since 2025-06-11
//     */
//    @ApiOperation(value = "详情")
//    @RequestMapping(value = "/info", method = RequestMethod.GET)
//    public CommonResult<AssistantMessage> info(@RequestParam(value = "id") Integer id) {
//        AssistantMessage assistantMessage = assistantMessageService.getById(id);
//        return CommonResult.success(assistantMessage);
//    }
}



